﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLab.Utility;
using System.Windows.Controls;
using AvalonDock;
using System.Windows.Input;
using Microsoft.Practices.Prism.Commands;

namespace QLab.Controllers
{
	/// <summary>
	/// Klasa koja mora biti nasledjena da bi odgovarajuci podaci mogli da budu prikazani kao tab
	/// </summary>
	public class TabBase : DocumentContent
	{
		private readonly string _tabHeaderPath;		//Koji ce property biti bindovan u title
		private readonly UserControl _view;			//Kontrola koja prikazuje sadrzaj unutar taba

		private ICommand _saveCommand;

		public TabBase(UserControl view)
		{
			_view = view;
			base.Content = view;

			this.Closing += new EventHandler<System.ComponentModel.CancelEventArgs>(TabBase_Closing);
			this.Closed += new EventHandler(TabBase_Closed);

			_saveCommand = new DelegateCommand(Save, CanSaveExecute);
		}

		public TabBase(UserControl view, string tabHeaderPath)
		{
			_view = view;
			_tabHeaderPath = tabHeaderPath;

			view.DataContext = this;
		}

		#region Properties

		public UserControl View	{ get { return _view; }	}

		public string TabHeaderPath	{ get { return _tabHeaderPath; } }

		public ICommand SaveCommand { get { return _saveCommand; } }

		#endregion

		#region Methods

		protected virtual bool CanSaveExecute()
		{
			return true;
		}
		protected virtual void Save()
		{

		}

		#endregion


		#region Event Handlers

		void TabBase_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			
		}

		void TabBase_Closed(object sender, EventArgs e)
		{
			//MainWindowController.Instance().TabController.RemoveTab(this);
		}

		#endregion

		
	}
}

